<?php if (!defined('BASIC_PATH')) exit; ?>
<?php
$info = wb_get_json($_GET['sid']);
require('header.php');
?>
    <div class="p-3 mb-4 bg-light rounded-3">
        <div class="container-fluid">

            <?php if (empty($info)): ?>
                <div class="alert alert-danger text-center mt-5" role="alert">
                    文件可能已经过期，或已超过下载限制了！
                </div>
                <form>
                    <div class="input-group mb-5" style="max-width: 500px;margin: 0 auto;">
                        <input type="text" name="sid" class="form-control" placeholder="请输入提取码">
                        <button class="btn btn-outline-secondary" type="submit" id="button-addon2">提交</button>
                    </div>
                </form>
            <?php else: ?>
                <h3 class="py-3 border-bottom fs-4">提取码：<strong class="text-danger fs-3"><?php echo $info['sid']; ?></strong>
                    <small class="fs-6 mx-3 text-black-50 ">时间：<span class="fw-light"><?php echo date('Y-m-d H:i:s',$info['time']); ?></span></small>
                </h3>

                <?php
                if ($info['type'] == 2) {
                    echo "<div class='my-2 text-box border mb-3 border-4 rounded-3 p-2 bg-white position-relative'><pre>{$info['wordtext']}</pre><span class=\"bd-clipboard\ position-absolute top-0 end-0\"><button type=\"button\" class=\"btn-clipboard\" title=\"复制到剪切板\">复制</button></span></div>";
                } else {
                    ?>
                    <div class="fs-6 text-black-50 mb-3 fw-light">共找到 <strong><?php echo count($info['files']); ?></strong> 个文件
                    </div>
                    <div class="row">
                        <?php foreach ($info['files'] as $key => $file): ?>
                            <div class="col-sm-6 mb-4">
                                <div class="card">
                                    <div class="card-body">
                                        <h5 class="card-title">文件名：<span class="text-success"><?php echo $file['name']; ?></span></h5>
                                        <p class="card-text">尺寸：<span class="text-dark"><?php echo round($file['size'] / 1000 / 1000, 2); ?>
                                                MB</span></p>
                                        <a href="download.php?sid=<?php echo $info['sid']; ?>&i=<?php echo $key; ?>"
                                           class="btn btn-primary w-50">下载</a>
                                    </div>
                                </div>
                            </div>
                        <?php endforeach; ?>
                    </div>
                    <?php

                }
            endif; ?>


        </div>
    </div>
    <div class="row align-items-md-stretch">
        <div class="col-md-12">
            <?php require('info-list.php'); ?>
        </div>
    </div>

    <script>
        let d = new ClipboardJS('.btn-clipboard', {
            target: function (a) {
                return a.parentNode.previousSibling
            }
        });
        d.on('success', function (a) {
            console.log(a);
            $('.btn-clipboard').text('复制文本成功');
            a.clearSelection()
        });
    </script>
<?php require('footer.php'); ?>